package com.zxc.shortlink.task;

import com.zxc.shortlink.component.ThreadPoolComponent;
import com.zxc.shortlink.component.data.ShortLinkComponentData;
import com.zxc.shortlink.pojo.enums.LinkMappingStateEnum;
import com.zxc.shortlink.service.LinkMappingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
* @author zxc_user
* @date 2022/3/24 14:52
* @version 1.0
* @description 短链接任务
**/
@Component
@Slf4j
public class ShortLinkTask implements Runnable {

    @Resource
    private ThreadPoolComponent threadPoolComponent;
    @Resource
    private LinkMappingService linkMappingService;
    @Resource
    private ShortLinkComponentData shortLinkComponentData;


    @PostConstruct
    public void init() {
        threadPoolComponent.getShortLinkThreadPool().execute(this);
    }

    @Override
    public void run() {
        //查询数据
        List<String> shortLink = linkMappingService.queryAllShortLink(LinkMappingStateEnum.ENABLE);
        //设置到布隆过滤器中
        shortLinkComponentData.setData(shortLink);

        log.info("加载布隆过滤器完成");
    }
}
